#include <iostream>
#include <algorithm>
#include <list>
#include <iterator>

using namespace std;

int iArray[5] = {1, 2, 3, 4, 5};

void display(list<int> &l, const char *s);

int main()
{
    list<int> iList;

    //copy iArray backwards into iList
    copy(iArray, iArray+5, front_inserter(iList));
    display(iList, "Brfore find and copy");

    //locate value 3 in iList
    list<int>::iterator p = find(iList.begin(), iList.end(), 3);

    //copy first two iArray values to iList ahead of p
    copy(iArray, iArray+2, inserter(iList, p));
    display(iList, "After find and copy");
    
    return 0;
}

void display(list<int> &l, const char *s)
{
    cout << s << endl;
    copy(l.begin(), l.end(), ostream_iterator<int>(cout, " "));
    cout << endl;
}
